package com;

/***
 * @title $NAME
 * @description <TODO description class purpose>
 * @author liyanzhen
 * @version 这是一个循环优化策略代码
 * @create 2024/6/15 21:29
 **/
public class 达夫设备 {
    public static void main(String[] args) {
        int a = 0;
        long count = 10000000000L;
        // 计算0~100000000
        long start = System.currentTimeMillis();
        for (long i = 0L; i < count; i++) {
            a = 100 * 100 / 100 * 100 / 100;
        }
        long timeConsuming = System.currentTimeMillis() - start;
        System.out.println("共耗时" + timeConsuming + "毫秒：");

        // com.达夫设备 - 优化
        start = System.currentTimeMillis();
        long n = (count + 7) / 8;
        int s = (int) (count % 8);
        switch (s){
            case 0:  a = 100 * 100 / 100 * 100 / 100;
            case 7:  a = 100 * 100 / 100 * 100 / 100;
            case 6:  a = 100 * 100 / 100 * 100 / 100;
            case 5:  a = 100 * 100 / 100 * 100 / 100;
            case 4:  a = 100 * 100 / 100 * 100 / 100;
            case 3:  a = 100 * 100 / 100 * 100 / 100;
            case 2:  a = 100 * 100 / 100 * 100 / 100;
            case 1:  a = 100 * 100 / 100 * 100 / 100;
        }
        while (--n > 1){
            a = 100 * 100 / 100 * 100 / 100;
            a = 100 * 100 / 100 * 100 / 100;
            a = 100 * 100 / 100 * 100 / 100;
            a = 100 * 100 / 100 * 100 / 100;
            a = 100 * 100 / 100 * 100 / 100;
            a = 100 * 100 / 100 * 100 / 100;
            a = 100 * 100 / 100 * 100 / 100;
            a = 100 * 100 / 100 * 100 / 100;
        }
        timeConsuming = System.currentTimeMillis() - start;
        System.out.println("共耗时" + timeConsuming + "毫秒：");
    }
}